package ru.mera.aaclog.db;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

/**
 * @version 1.0 2/03/2013
 * @author anavdeev
 */
@Entity
@Table(name="logs")
@NamedQueries( {
    @NamedQuery(name = LogHeader.GET_ALL, 
                query = "SELECT l FROM LogHeader l ORDER BY l.date desc, l.name asc"),
    @NamedQuery(name = LogHeader.GET_BY_ID, 
                query = "SELECT l FROM LogHeader l WHERE l.id = ?1")
} )
public class LogHeader implements Serializable  {

    public static final String GET_ALL = "getAllLogs";
    public static final String GET_BY_ID = "getLog";

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "log_id")
    private int id;
    
    @OneToMany(mappedBy="log")
    @OnDelete(action=OnDeleteAction.CASCADE)
    private Set<MessageHeader> messages;

    @Column(name = "log_name", nullable = false, columnDefinition="", length = 100)
    private String name;
    
    @Column(name = "log_date")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date date;
    
    @Column(name = "log_filename", nullable = false, columnDefinition="", length = 256)
    private String filename;

    public LogHeader() {
        // serializable ctor
    }

    public LogHeader(int id) {
        this.id = id;
    }

    public LogHeader(String name, Date date, String filename) {
        this.name = name;
        this.date = date;
        this.filename = filename;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public Set<MessageHeader> getMessages() {
        return messages;
    }

    public void setMessages(Set<MessageHeader> messages) {
        this.messages = messages;
    }

    public String getFilename() {
        return filename;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }

    public int getSize() {
        return 0;
    }

}
